fix: 修复代码块吞正文(闭合围栏被误改为 ```text) - #3
Open
turinglambdaai wants to merge 1 commit into
Open
Conversation
crawler.py 的 format_content() 围栏正则 ^```\w*$ 无法识别含特殊
字符的语言标记(如 ```c#、```c++,因 # 不属于 \w),导致开启围栏
漏识别、状态机不翻转。随后遇到合法的闭合围栏 ``` 时被误判为开启
围栏,改写成 ```text —— 而 CommonMark 规定闭合围栏不能带 info
string,于是 ```text 成了新代码块的起始标记,后续所有正文被吞进
未闭合的代码块。
影响 3 篇文章共 16 处坏围栏:
- Kotlin 和 Checked Exception.md(1 处)
- C# 的 IDisposable 接口.md(5 处)
- 对 Rust 语言的分析.md(10 处)
修复:
1. crawler.py: 围栏正则改为 ^(\s{0,3})(`{3,})([^`]*)$,可识别任意
语言标记;状态机区分开启/闭合分支,闭合围栏不再被改写。
2. 新增 scripts/fix_code_fences.py: 用修复后的状态机扫描全部文章,
将错误的 ```text 闭合围栏还原为裸 ```(幂等,已跑 0 改动验证)。
3. 修复 3 篇文章的 16 处坏数据。
验证:用项目 markdown-it 重新渲染全部 173 篇文章,0 处代码块吞正文。
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
从「在这种疑虑的情况下,你就不得不做最坏的打算,你就得把代码写成:」开始,下面所有正文被包裹在代码块里无法正常渲染。
根因
crawler.py的format_content()围栏正则^\``\w*$无法识别含特殊字符的语言标记(如c# `、`c++,因为#/+不属于\w`)。因果链:
```c#开 /```闭)```c#不匹配正则 → 开启围栏漏识别 → 状态机in_code_block不翻转```→ 状态机误判为「开启」→ 满足not in_code_block and stripped == "\``"→ 改写成```text ````text成了新代码块的起始标记 → 后续正文全部被吞影响范围
3 篇文章、共 16 处坏围栏(用项目 markdown-it 实际渲染检测):
Kotlin 和 Checked Exception.md(1 处)← 用户报告C# 的 IDisposable 接口.md(5 处)对 Rust 语言的分析.md(10 处)修复
1.
scripts/crawler.py— 修围栏正则与状态机^(\s{0,3})(\{3,})([^\`])$:可识别任意语言标记(c#、c++、f#…),[^\`]同时排除行内代码(code`)text;闭合→保持不动2.
scripts/fix_code_fences.py— 一次性数据修复(新增)用修复后的状态机扫描全部文章,将错误的
```text闭合围栏还原为裸```。幂等(已验证再跑 0 改动)。3. 修复 3 篇文章的 16 处坏数据
验证
用项目实际
markdown-it重新渲染全部 173 篇文章,0 处代码块吞正文。备注
本 PR 只修代码块渲染 bug。AdSense「收益损失风险」警告经排查不在代码层(ads.txt 内容正确、HTTP 200、AdSense 爬虫 UA 也返回 200),属账号侧问题。